﻿<link href="~/css/site.css" rel="stylesheet" />
<script src="~/vue/dist/vue.global.js"></script>
<link href="~/element-plus/dist/index.css" rel="stylesheet" />
<script src="~/element-plus/dist/index.full.js"></script>
<script src="~/axios/dist/axios.js">    </script>
<div id="app">
    <el-row>
        <el-col :span="24">
            您正在做的业务是：人力资源--权限管理--用户管理
        </el-col>
    </el-row>
    <el-row>
        <el-col :span="24" style="text-align: right">
            <el-button type="primary" v-on:click="Add()">添加</el-button>
        </el-col>
    </el-row>
    <el-row style="height: 10px"></el-row>
    <el-row>
        <el-col :span="24">
            <el-table :data="data" border style="width: 100%">
                <el-table-column prop="uId" label="用户编号"></el-table-column>
                <el-table-column prop="uName" label="用户名称"></el-table-column>
                <el-table-column prop="uTrueName" label="真实姓名"></el-table-column>
                <el-table-column prop="uPassWord" label="用户密码"></el-table-column>
                <el-table-column prop="rolesName" label="用户身份"></el-table-column>
                <el-table-column label="操作">
                    <template #default="scope">
                        <el-button v-on:click="Xg(scope.row)" type="primary">修改</el-button>
                        <el-button v-on:click="Sc(scope.row)" type="danger">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-col>
    </el-row>
    <el-row>
        <div id="pageDiv">
            <span class="span1">  总数：{{count}} 例    当前第{{a}}页 /每页显示 {{b}} 条    共 {{page}} 页  </span>
            <div class="div">
                <button v-on:click="HomePage()">首页</button>
                <button v-on:click="PreviousPage()">上一页</button>
                <button v-on:click="NextPage()">下一页</button>
                <button v-on:click="LastPage()">尾页</button>
                跳到第
                <input type="text" style="width: 30px;height: 20px;" v-model="pages">
                <a>页</a>
                <button v-on:click="GoTo()">
                    <img src="~/images/go.bmp" />
                </button>
            </div>
        </div>
    </el-row>


    <el-dialog v-model="dialogVisible"
               title="删除"
               width="500"
               :before-close="handleClose">
        <span>确定删除该数据吗?</span>
        <template #footer>
            <div class="dialog-footer">
                <el-button v-on:click="CFFKdelete()" type="danger">删除</el-button>
                <el-button type="primary" v-on:click="dialogVisible = false">
                    取消
                </el-button>
            </div>
        </template>
    </el-dialog>
</div>

<script type="text/javascript">
    const { createApp, ref, reactive,computed } = Vue
    const { ElMessage } = ElementPlus
    var app = createApp({
        setup() {
            const a = ref(1)//当前页数
            const b = ref(5)//每页显示数
            const count = ref(0)//数据总数
            const data = ref([])
            const page = computed(() => {
                return Math.ceil(count.value / b.value)
            });//总页数
            const pages = ref()//跳转到的页数
            const dialogVisible = ref(false)
            function Show() {
                axios.get("/Roles/HRFill1", {
                    params: {
                        a: a.value,
                        b: b.value,
                    }
                })
                    .then(res => {
                        data.value = res.data
                    })
                    .catch(err => {
                        console.log(err);
                    })
                axios.get("/Roles/HRCount")
                    .then(res => {
                        count.value = res.data
                    })
                    .catch(err => {
                        console.log(err);
                    })
            }
            function Add() {
                window.location.href = "/Roles/UserAddYM"
            }
            function Xg(val) {
                if (val.rolesName != "系统管理员") {
                    window.location.href = "/Roles/UserUpdateYM?id=" + val.uId
                } else {
                    alert("不能对系统管理员进行操作！！！")
                }
                // window.location.href = "/Permissions/RoleUpdateYM?id=" + val
            }
            function Sc(val) {
                if (val.rolesName != "系统管理员") {
                    if (confirm("是否确认删除？")) {
                        axios.delete("/Roles/UserDelete", {
                            params: {
                                uid: val.uId
                            }
                        })
                            .then(res => {
                                ElMessage({
                                type: 'success',
                                message: '删除成功！'});
                                setInterval(()=>{
                                    Show()
                                },1000)
                            })
                            .catch(err => {
                                console.log(err);
                            })
                    }
                } else {
                    alert("不能对系统管理员进行操作！！！")
                }
            }
            Show()
                        //首页
            function HomePage() {
                a.value = 1;
                Show();
            }

            //上一页
            function PreviousPage() {
            if (a.value != 1) {
                    a.value -= 1;
                    Show();
                }
            }

            //下一页
            function NextPage() {
            if (a.value != page.value) {
                    a.value += 1;
                    Show();
                }
            }

            //尾页
            function LastPage() {
                a.value = page.value;
                Show();
            }


            //转到页数
            function GoTo() {
                if (!isNaN(pages.value)) {
                    if (pages.value > page.value || pages.value < 1) {
                        alert("输入的页数有误！")
                        pages.value = ""
                    } else {
                        a.value = Number(pages.value)
                        pages.value = ""
                        Show();
                    }
                } else {
                    alert('你输入的不是数字！')
                }
            }
            return {
                a,
                b,
                count,
                data,
                Show,
                Add,
                Xg,
                Sc,
                page,pages,HomePage,LastPage,NextPage,PreviousPage,GoTo,dialogVisible
            }
        }
    })
    app.use(ElementPlus)
    app.mount('#app')
</script>

<style scoped>
    body {
        background-color: #ffffcc;
    }

    #pagination {
        position: absolute;
        right: 0px;
        top: 10px;
    }

    body {
        background-color: #ffffcc;
    }

    #pageDiv {
        padding: 10px;
    }

    .div {
        width: 410px;
        height: 25px;
        /* background-color: black; */
        margin-left: 400px;
        margin-top: -26px;
        line-height: 25px;
    }

    .span1 {
        font-size: 15px;
    }

    .div button {
        margin: 0 5px;
        background-color: #00000000;
        border: 0px;
    }

    .div a {
        margin: 0 5px;
    }

    a {
        text-decoration: none;
        color: white;
    }

    tbody, td, tfoot, th, thead, tr {
        border-color: inherit;
        background-color: #ffffbb;
        border-style: solid;
        border-width: 0;
    }
</style>